﻿@using BBICMS.Infrastructure
@model BBICMS.Model.ViewModel.Back.BlogListVM

@{
    ViewBag.Title = "新闻分类";
    ViewBag.PageTitle = ViewBag.Title + "_内容";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}




    <div class="panel panel-default">
        <header class="panel-heading">
            <span class="glyphicon glyphicon-file"></span> @ViewBag.Title         
        </header>

        

        <section class="panel-body">
            <div class="text-right">
                <a class="btn btn-primary" href="@Url.Action("AddBlog")"><i class="glyphicon glyphicon-plus"></i> 添加新闻分类</a>
                <a class="btn btn-default" href="@Url.Action("AddPost")"><i class="glyphicon glyphicon-plus"></i> 添加新闻</a>
            </div>
        </section>

            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>                          
                          
                            <th>
                                主题
                            </th>
                          
                            <th>
                                排序
                            </th>
                            <th>
                                创建日期
                            </th>
                            <th>
                                操作
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var Blog in Model.Blogs)
                        {
                            <tr class="first">
                                <td>
                                    @Blog.Title
                                </td>
                                <td>
                                    @Blog.Importance
                                </td>
                              
                           
                                <td>@Blog.AddedDate.ToShortDateString()</td>
                                <td>
                                    <a href="@Url.Action("EditBlog", new { Id = Blog.Id })" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i></a>
                                    <a href="@Url.Action("DeleteBlog", new { Id = Blog.Id })" class="btn btn-xs btn-danger delete-site"><i class="glyphicon glyphicon-trash"></i></a>
                                </td>
                            </tr>
                        }

                    </tbody>

                </table>



            </div>
       

        <footer class="panel-footer">
            <ul class="pagination">
                @Html.PageLinks(Model.PagingInfo, x => Url.Action("Blogs", new { Page = x }))
            </ul>
        </footer>


    </div>

<!-- end main container -->
@section footer {

    <script>

        $(function () {
            //当前菜单;
            $('.mainmenu>li:nth-of-type(3)').addClass('nav-open').find('.submenu li:nth-of-type(2) a').addClass('active');


            //删除数据
            $('.delete-site').click(function (e) {
                var url = $(this).attr('href');
                var that = $(this);
               // console.log(url);
                /*DELETE*/
                $.ajax({
                    url: url,
                    dataType: "json",
                    type: "DELETE",
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify({}),
                    async: true,
                    processData: false,
                    cache: false,
                    success: function (data) {
                        if (data) {
                            toastr.success('分类已删除成功！', '删除分类');
                            that.closest('tr').remove();
                        } else {
                            toastr.error('分类删除失败！', '删除分类');
                        }
                    },
                    error: function (xhr) {
                        toastr.error('分类删除失败！', '删除分类');
                    }
                });

                e.preventDefault();
            })

        });
    </script>

}